package com.ruoyi.mes.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mes.domain.ProductionTasks;
import com.ruoyi.mes.service.IProductionTasksService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 生产任务管理Controller
 * 
 * @author ruoyi
 * @date 2025-01-09
 */
@RestController
@RequestMapping("/mes/tasks")
public class ProductionTasksController extends BaseController
{
    @Autowired
    private IProductionTasksService productionTasksService;

    /**
     * 查询生产任务管理列表
     */
    @PreAuthorize("@ss.hasPermi('mes:tasks:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProductionTasks productionTasks)
    {
        startPage();
        List<ProductionTasks> list = productionTasksService.selectProductionTasksList(productionTasks);
        return getDataTable(list);
    }

    /**
     * 导出生产任务管理列表
     */
    @PreAuthorize("@ss.hasPermi('mes:tasks:export')")
    @Log(title = "生产任务管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductionTasks productionTasks)
    {
        List<ProductionTasks> list = productionTasksService.selectProductionTasksList(productionTasks);
        ExcelUtil<ProductionTasks> util = new ExcelUtil<ProductionTasks>(ProductionTasks.class);
        util.exportExcel(response, list, "生产任务管理数据");
    }

    /**
     * 获取生产任务管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('mes:tasks:query')")
    @GetMapping(value = "/{taskId}")
    public AjaxResult getInfo(@PathVariable("taskId") Long taskId)
    {
        return success(productionTasksService.selectProductionTasksByTaskId(taskId));
    }

    /**
     * 新增生产任务管理
     */
    @PreAuthorize("@ss.hasPermi('mes:tasks:add')")
    @Log(title = "生产任务管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductionTasks productionTasks)
    {
        return toAjax(productionTasksService.insertProductionTasks(productionTasks));
    }

    /**
     * 修改生产任务管理
     */
    @PreAuthorize("@ss.hasPermi('mes:tasks:edit')")
    @Log(title = "生产任务管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductionTasks productionTasks)
    {
        return toAjax(productionTasksService.updateProductionTasks(productionTasks));
    }

    /**
     * 删除生产任务管理
     */
    @PreAuthorize("@ss.hasPermi('mes:tasks:remove')")
    @Log(title = "生产任务管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{taskIds}")
    public AjaxResult remove(@PathVariable Long[] taskIds)
    {
        return toAjax(productionTasksService.deleteProductionTasksByTaskIds(taskIds));
    }
}
